<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="utf-8">
    <meta name="author" content="lzy">
    <title>lzy-</title>
    <script src="jquery-3.1.1.js"></script>
    <style>
        html,body{
            height: 100%;
        }
        body{
            margin: 0;
        }
        main{
            width: 600px;
            height: 200px;
            margin: 100px auto;
        }
        main .header{
            width: 100%;
            height: 30px;
        }
        main .header .left{
            float: left;
            color: blue;
        }
        main .header .right{
            float: right;
        }
        textarea{
            display: block;
            width: 100%;
        }
        button{
            display: block;
            height: 30px;
            width: 80px;
            background-color: darkorange;
            border-style: none;
            float: right;
            border-radius: 5px;
            color: white;
            font-size: 16px;
            margin-top: 5px;
        }
        span{
            color: orange;
        }
    </style>
</head>
<body>
    <main>
        <div class="header">
            <div class="left">有什么新鲜事告诉大家</div>
            <div class="right" id="wordCheck">广告.........</div>
        </div>
        <textarea name="" id="text" cols="40" rows="5"></textarea>
        <button type="button" value="发布">发布</button>
    </main>
</body>
</html>
<script> 
    $('textarea').focus(function(){
        $('.right').html('可以发布超过'+'<span>'+"140"+'</span>'+'字的微博');
    });
    $('textarea').keyup(function show(){
        len = maxstrlen;
        var str=$(this).val();
        myLen=getStrleng(str)
        var wck=$('#wordCheck');
        if (myLen > len * 2) {
            c.value = str.substring(0, i + 1);
        }
        else {
            wck.html('输入了'+Math.floor( myLen / 2)+'个字'); 
        }        
    }); 
    var maxstrlen=140;
    function getStrleng(str) {
        myLen = 0;
        i = 0;
        for (i; (i < str.length) && (myLen <= maxstrlen * 2); i++) {
            if (str.charCodeAt(i) > 0 && str.charCodeAt(i) < 128)
                myLen++;
            else
                myLen += 2;
        }
        console.log(myLen);
        return myLen;
    }  
      
</script>